package com.nuoniu.sibanyun.mapper.production;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.dto.VProductionWorkDetailSearchDto;
import com.nuoniu.sibanyun.entity.production.VProductionDispatchMain;
import com.nuoniu.sibanyun.entity.vo.UnFinishProductionDispatchMainVo;
import com.nuoniu.sibanyun.entity.vo.UnFinishProductionWorkInventoryDetailVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 生产制造——派工单 Mapper 接口
 * </p>
 *
 * @author 小啊刚
 * @since 2021-04-19
 */
public interface VProductionDispatchMainMapper extends BaseMapper<VProductionDispatchMain> {

    @Select("SELECT * FROM ma_dispatch_list WHERE company_id = #{companyId} AND account_id = #{accountId} ORDER BY id DESC LIMIT 1")
    VProductionDispatchMain getLastId(Integer companyId, Integer accountId);
    @Select("SELECT * FROM ma_dispatch_list WHERE company_id = #{companyId} AND account_id = #{accountId} ORDER BY id ASC LIMIT 1")
    VProductionDispatchMain getFirstId(Integer companyId,Integer accountId);
    @Select("SELECT * FROM ma_dispatch_list WHERE company_id = #{companyId} AND account_id = #{accountId} AND id < #{currentId} ORDER BY id DESC LIMIT 1")
    VProductionDispatchMain getPreId(Integer companyId,Integer accountId,Long currentId);
    @Select("SELECT * FROM ma_dispatch_list WHERE company_id = #{companyId} AND account_id = #{accountId} AND id > #{currentId} ORDER BY id ASC LIMIT 1")
    VProductionDispatchMain getNextId(Integer companyId,Integer accountId,Long currentId);


    @Select("select voucher_code from ma_dispatch_list where company_id=#{companyId} and date_format(create_date, #{dateStr})=date_format(now(), #{dateStr}) order by create_date desc limit 1")
    String getNewestCode(Integer companyId, String dateStr);


    int getMaxDispatchTimes(Integer companyId,Integer accountId,Long workDetailId);

    /**
     * 获取 未完成 派工单明细
     * @param companyId
     * @param accountId
     * @param  businessType 业务类型
     * @param productionDispatchMainSearchDto
     * @return
     */
    List<UnFinishProductionDispatchMainVo> listUnFinishProductionWorkDetailVo(Integer companyId, Integer accountId, Integer businessType, @Param("dto") VProductionWorkDetailSearchDto productionDispatchMainSearchDto);

    /**
     * 获取 未完成 派工单 （未领完）材料明细
     * @param companyId
     * @param accountId
     * @param productionDispatchMainSearchDto
     * @return
     */
    List<UnFinishProductionWorkInventoryDetailVo> listUnFinishProductionWorkInventoryDetailVo(Integer companyId, Integer accountId, Integer businessType, @Param("dto") VProductionWorkDetailSearchDto productionDispatchMainSearchDto);











}
